package com.example.Housekeeping.controller;

import com.example.Housekeeping.domain.Bo.AddHouseKeeperBo;
import com.example.Housekeeping.domain.Bo.HouseKeeperListBo;
import com.example.Housekeeping.domain.HouseKeeper;
import com.example.Housekeeping.domain.Vo.HouseKeeperVo;
import com.example.Housekeeping.service.IHouseKeeperService;
import com.example.JavaDemo.domain.Community;
import com.example.comon.domain.LoginUser;
import com.example.comon.domain.R;
import com.example.comon.utils.UserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/HouseKeeper")
@Api(value = "houseKeeper",tags = "家政员工控制器")
public class HouseKeeperController {
    @Autowired
    private IHouseKeeperService houseKeeperService;

    @GetMapping("/getHouseKeeperList")
    @ApiOperation("获取家政员工订单列表")
    public R<List<HouseKeeperVo>> getHouseKeeperList(HouseKeeperListBo bo){
        HouseKeeper houseKeeper = new HouseKeeper();
        houseKeeper.setWorkName(bo.getWorkName());
        houseKeeper.setPhoneNum(bo.getPhoneNum());
        List<HouseKeeperVo> list =  houseKeeperService.selectHouseKeeper(houseKeeper);
        return R.success(list);
    }
    @GetMapping("/getHouseKeeperById")
    @ApiOperation("根据id获取家政员工订单")
    public R<List<HouseKeeperVo>> getHouseKeeperById(HouseKeeperListBo bo){
        HouseKeeper houseKeeper = new HouseKeeper();
        houseKeeper.setHousekeeperId(bo.getHousekeeperId());

        List<HouseKeeperVo> list =  houseKeeperService.selectHouseKeeper(houseKeeper);
        return R.success(list);
    }
    @PostMapping("/addHouseKeeper")
    @ApiOperation("增加员工")
    public R<List<Community>> addHouseKeeper(@RequestBody AddHouseKeeperBo bo){
        HouseKeeper houseKeeper = new HouseKeeper();
        houseKeeper.setCompanyId(bo.getCompanyId());
        houseKeeper.setPhoneNum(bo.getPhoneNum());
        houseKeeper.setWorkName(bo.getWorkName());
        houseKeeper.setExperience(bo.getExperience());

        LoginUser loginUser = UserUtil.getLoginUser();//获取当前登录账号
        houseKeeper.setCreateBy(Integer.valueOf(loginUser.getUserId()));
        houseKeeperService.addHouseKeeper(houseKeeper);
        return R.success();
    }

    @PostMapping("/updateHouseKeeperById")
    @ApiOperation("修改员工信息")
    public R updateHouseKeeperById(@RequestBody HouseKeeper houseKeeper){
//        LoginUser loginUser = UserUtil.getLoginUser();//获取当前登录账号
//        houseKeeper.setUpdateBy(Integer.valueOf(loginUser.getUserId()));
        houseKeeperService.updateHouseKeeperById(houseKeeper);
        return R.success();
    }

    @DeleteMapping("/delHouseKeeperById")
    @ApiOperation("删除员工信息")
    public R delHouseKeeperById(String id){
        houseKeeperService.delHouseKeeperById(id);
        return R.success();
    }
}
